﻿using NUnit.Framework;

namespace System.Data.MdxClient.Tests
{
    [TestFixture()]
    public class MdxConnectionStringBuilderTests
    {
        [Test()]
        public void CanParseProvidedConnectionString()
        {
            var connectionString = "Data Source=myServerAddress;Catalog=myDataBase;Integrated Security=SSPI";
            var builder = new MdxConnectionStringBuilder(connectionString);
            Assert.That(builder.DataSource, Is.EqualTo("myServerAddress"));
            Assert.That(builder.InitialCatalog, Is.EqualTo("myDataBase"));
            Assert.That(builder.IntegratedSecurity, Is.EqualTo(IntegratedSecurity.Sspi));

            connectionString = "Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI";
            builder = new MdxConnectionStringBuilder(connectionString);
            Assert.That(builder.DataSource, Is.EqualTo("myServerAddress"));
            Assert.That(builder.InitialCatalog, Is.EqualTo("myDataBase"));
            Assert.That(builder.IntegratedSecurity, Is.EqualTo(IntegratedSecurity.Sspi));
        }

        [Test()]
        public void CanCreateConnectionString()
        {
            var builder = new MdxConnectionStringBuilder();
            builder.InitialCatalog = "myDataBase";
            builder.DataSource = "myServerAddress";
            builder.IntegratedSecurity = IntegratedSecurity.Sspi;

            var connectionString = builder.ConnectionString;
            Assert.That(connectionString, Is.EqualTo("Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=Sspi"));
        }

        [Test()]
        public void ToStringShouldReturnConnectionString()
        {
            var builder = new MdxConnectionStringBuilder();
            builder.InitialCatalog = "myDataBase";
            builder.DataSource = "myServerAddress";
            Assert.AreEqual(builder.ConnectionString, builder.ToString());
        }
    }
}
